package ztc.servlet;

import ztc.common.StuBean;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by ztc on 16-4-20.下午4:08
 */
public class Logout extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session=request.getSession();
        ServletContext application=this.getServletContext();
        ConcurrentHashMap<String,ConcurrentHashMap<String,StuBean>> aMap=
                (ConcurrentHashMap<String, ConcurrentHashMap<String, StuBean>>) application.getAttribute("sessionID");
        if(aMap!=null)
            aMap.remove(session.getId());
        session.invalidate();
        response.sendRedirect("/users/login.jsp");
    }
}
